/*
 * animation.cpp
 *
 *  Created on: Oct 15, 2011
 *      Author: bryan
 */
#pragma once

#include "globals_.h"
#include "figure.h"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>

void animateFigure(Figure * ptr){
	float V = ptr->Vi + (g*sec_to_ms(ptr->_time));

	if( ptr->center.second <= 0  && ptr->going_up) return;

	if( ptr->center.second <= 0  && !ptr->going_up){
		float Vf = sqrt(2.0*abs(g)*ptr->max_h);
		ptr->Vi = restitution*Vf;
		if(round2(ptr->Vi)==0) return;
		ptr->h = 0.0;
		ptr->center.second = 0.0;
		ptr->_time = 0;
		ptr->max_h = pow(ptr->Vi,2)/(2.0*abs(g));
		ptr->going_up = true;
	}
	else if(round2(V) == 0){
		ptr->going_up = false;
	}
	++ptr->_time;
	ptr->center.second = ptr->h + ( ptr->Vi * sec_to_ms(ptr->_time) ) + ( g * pow(sec_to_ms(ptr->_time),2.0) ) / 2.0;
}
